package com.srwl.mytx.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.srwl.mytx.widget.GoodsClassfyCheckableItem;

import java.util.List;

/**
 * Created by dahai2070 on 2016/11/26 0026.
 */
public class GoodsClassfyAdapterForListView extends ArrayAdapter {
    List<String> classfyList;
    Context context;
    int resource;
    private int temp = -1;//记录每次点击的按钮的Id
    private Activity activity;
    boolean isRefresh = false;

    public GoodsClassfyAdapterForListView(Context context, int resource, List<String> classfyList, Activity activity) {
        super(context, resource, classfyList);
        this.classfyList = classfyList;
        this.resource = resource;
        this.context = context;
        this.activity = activity;
    }

    public void refreshItem(boolean isRefresh ,int checkedIndex) {
        this.isRefresh = isRefresh;
        this.temp=checkedIndex;
    }

    @Override
    public void add(Object object) {
        super.add(object);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final GoodsClassfyCheckableItem itemView;
        if (convertView == null) {
            itemView = new GoodsClassfyCheckableItem(context, null);
        } else {
            itemView = (GoodsClassfyCheckableItem) convertView;
        }
        itemView.setData(classfyList.get(position));
//        if (isRefresh&&temp==position){
//            isRefresh=false;
//           itemView.setChecked(false);
//        }
//        itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onExtendMenuItemClick(View v) {
//                temp=position;
//                if (itemView.isChecked()) {
//                    itemView.toggle();
//                }
//            }
//        });
        return itemView;
    }

    @Override
    public int getPosition(Object item) {
        return super.getPosition(item);
    }

    @Override
    public Object getItem(int position) {
        return super.getItem(position);
    }

    @Override
    public int getCount() {
        return classfyList.size();
    }

    class Holder {
        TextView tv_classfy;
    }

}
